<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>父组件与子组件</title>
</head>

<body>

  <div id="app">
    <cpn2></cpn2>
  </div>

  <script src="../../js/vue.js"></script>
  <script>
    // 1. 创建第一个组件构造器
    const cpnC1 = Vue.extend({
      template: `
      <div>
        <h2>我是标题1</h2>
        <p>我是内容1，哇哈哈哈哈</p>
      </div>
      `
    })


    // 2. 创建第二个组件构造器
    const cpnC2 = Vue.extend({
      template: `
      <div>
        <h2>我是标题2</h2>
        <p>我是内容2，哇哈哈哈哈</p>
        <hr>
        <cpn1></cpn1>
      </div>
      `,
      // cpn1为cpn2的子组件, cpn2为cpn1父组件
      components: {
        cpn1: cpnC1
      }
    })


    const app = new Vue({
      el: '#app',
      components: {
        cpn2: cpnC2
      }
    })
  </script>
</body>

</html>